﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PMisuseAn.util;
using System.Collections.Specialized;

namespace PMisuseAn.behaviour.model
{
    [Serializable()]
    public class Threat
    {
        public Agent subjectAgent; //victim agent
        public Agent sendAgent;
        public Agent recieveAgent;
        public State message_s;
        public Transition message_t;
        public Policy violatedPolicy;
        public List<Object> violatingParameterisedContextInstances;
        public string rationalle;
        public string comments;
        public ListDictionary rationales;
        public DateTime timestamp;
        public VulnerableAggTransmission vulnTrans;
        public enum ThreatType {futureThreat, currentThreat};

        private ThreatType threatType_;
        public List<string> mitigationOptions;
        
        public Threat()
        {
            mitigationOptions = new List<string>();
            rationales = new ListDictionary();
        }

        public ThreatType threatType
        {
            get
            {
                return threatType_;
            }
            set
            {
                threatType_ = value;
            }
        }

        public void generateMitigationOptions()
        {

            //TODO: semantics for selecting mitigation options
            mitigationOptions.Add("IGNORE");
            if (message_s != null)
            {
                mitigationOptions.Add("ISOLATE " + message_s.name + " HENCEFORTH WHILE INTERACTING WITH " + sendAgent.agentName);
                mitigationOptions.Add("ISOLATE " + message_s.name + " EVENTUALLY WHILE INTERACTING WITH " + sendAgent.agentName);
                mitigationOptions.Add("ISOLATE " + message_s.name + " NEXT-TIME WHILE INTERACTING WITH " + sendAgent.agentName);
                mitigationOptions.Add("TODO: ISOLATE " + message_s.name + " HENCEFORTH WHILE INTERACTING WITH " + sendAgent.agentName+ " AND x");
                mitigationOptions.Add("TODO: ISOLATE " + message_s.name + " EVENTUALLY WHILE INTERACTING WITH " + sendAgent.agentName + " AND x");
                mitigationOptions.Add("TODO: ISOLATE " + message_s.name + " NEXT-TIME WHILE INTERACTING WITH " + sendAgent.agentName + " AND x");
                mitigationOptions.Add("TODO: ISOLATE " + message_s.name + " HENCEFORTH WHILE INTERACTING WITH " + sendAgent.agentName + " OR x");
                mitigationOptions.Add("TODO: ISOLATE " + message_s.name + " EVENTUALLY WHILE INTERACTING WITH " + sendAgent.agentName + " OR x");
                mitigationOptions.Add("TODO: ISOLATE " + message_s.name + " NEXT-TIME WHILE INTERACTING WITH " + sendAgent.agentName + " OR x");
                mitigationOptions.Add("ISOLATE " + message_s.name + " HENCEFORTH FOR ALL AGENTS");
                mitigationOptions.Add("ISOLATE " + message_s.name + " NEXT-TIME FOR ALL AGENTS");
                mitigationOptions.Add("ISOLATE " + message_s.name + " EVENTUALLY FOR ALL AGENTS");
                mitigationOptions.Add(" ");
            }

            else if (message_t != null)
            {
                mitigationOptions.Add("ISOLATE " + message_t.transitionName + " HENCEFORTH WHILE INTERACTING WITH " + sendAgent.agentName);
                mitigationOptions.Add("ISOLATE " + message_t.transitionName + " EVENTUALLY WHILE INTERACTING WITH " + sendAgent.agentName);
                mitigationOptions.Add("ISOLATE " + message_t.transitionName + " NEXT-TIME WHILE INTERACTING WITH " + sendAgent.agentName);
                mitigationOptions.Add("TODO: ISOLATE " + message_t.transitionName + " HENCEFORTH WHILE INTERACTING WITH " + sendAgent.agentName + " AND x");
                mitigationOptions.Add("TODO: ISOLATE " + message_t.transitionName + " EVENTUALLY WHILE INTERACTING WITH " + sendAgent.agentName + " AND x");
                mitigationOptions.Add("TODO: ISOLATE " + message_t.transitionName + " NEXT-TIME WHILE INTERACTING WITH " + sendAgent.agentName + " AND x");
                mitigationOptions.Add("TODO: ISOLATE " + message_t.transitionName + " HENCEFORTH WHILE INTERACTING WITH " + sendAgent.agentName + " OR x");
                mitigationOptions.Add("TODO: ISOLATE " + message_t.transitionName + " EVENTUALLY WHILE INTERACTING WITH " + sendAgent.agentName + " OR x");
                mitigationOptions.Add("TODO: ISOLATE " + message_t.transitionName + " NEXT-TIME WHILE INTERACTING WITH " + sendAgent.agentName + " OR x");
                mitigationOptions.Add("ISOLATE " + message_t.transitionName + " HENCEFORTH FOR ALL AGENTS");
                mitigationOptions.Add("ISOLATE " + message_t.transitionName + " NEXT-TIME FOR ALL AGENTS");
                mitigationOptions.Add("ISOLATE " + message_t.transitionName + " EVENTUALLY FOR ALL AGENTS");
                
            } 
                PolicyStatementAnalyser psa = new PolicyStatementAnalyser();
                psa.ifThenUnlessTokenisation(violatedPolicy.statement);

                mitigationOptions.Add("FORCE REQUIRED CONTEXT: " +psa.then_content);
                mitigationOptions.Add("FORFEIT POLICY FOR CURRENT TRANSMISSION");
                mitigationOptions.Add("FORFEIT POLICY FOR ALL TRANSMISSIONS");
                mitigationOptions.Add("[TODO] ADD STATE");
                mitigationOptions.Add("[TODO] REDIRECT VIA TRANSITION X");

        }
    }
}
